<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
<title>${appname}-<c:if test="${!empty sessionScope._local_node_session}">${sessionScope._local_node_session.nodeName}-</c:if>${si:ctname("NET_TYPE",sessionScope._netType)}</title>
<%@ include file="/WEB-INF/view/common/css_js_ace.jsp"%>
<%@ include file="/WEB-INF/view/common/css_js_ztree.jsp"%>
<script type="text/javascript"
	src="${ctx}/static/js/lib/nicescroll/jquery.nicescroll.min.js"></script>
<script type="text/javascript">
	$(function() {
		var dataType = '${param.dataType}';
		if(dataType == "request"){
			connRequestList();
		}else{
			nodeInfoList();
		}
	})
	function getNode(id) {
		$.ajax({
			type : "GET",
			dataType : "html",
			cache : false,
			url : _ctx + "/registry/node_info_detail.do",
			data : {
				selectedNodeId : id
			},
			 beforeSubmit: function(){
		           	$("#sbmBtn").attr("disabled","disabled");
		        },
			success : function(content) {
				$('#myModal').modal('show');
				$('#info').html(content);
			},
			error : function() {
				//ui.msg('信息加载错误', 0);
			}
		});
	}
	function getRequest(id) {
		$.ajax({
			type : "GET",
			dataType : "html",
			cache : false,
			url : _ctx + "/exch/conn_request_get.do",
			data : {
				id : id
			},
			success : function(content) {
				$('#myModal').modal('show');
				$('#info').html(content);
			},
			error : function() {
				ui.msg('信息加载错误', 0);
			}
		});
	}
	function nodeInfoList() {
		$.ajax({
			type : "GET",
			dataType : "html",
			cache : false,
			url : _ctx + "/registry/node_info_list.do",
			success : function(content) {
				$('#data').html(content);
				$('#requestList').removeClass("active");
				$('#nodeList').addClass("active");
			},
			error : function() {
				ui.msg('信息加载错误', 0);
			}
		});
	}
	function connRequestList() {
		$.ajax({
			type : "GET",
			dataType : "html",
			cache : false,
			url : _ctx + "/exch/conn_request_list.do",
			success : function(content) {
				$('#nodeList').removeClass("active");
				$('#requestList').addClass("active");
				$('#data').html(content);
			},
			error : function() {
				ui.msg('信息加载错误', 0);
			}
		});
	}
	function requestAudit(id) {
		var status = $("input:radio[name='status']:checked").val();
		var response = $("#response").val();
		$("#requestAuditBtn").attr("disabled","disabled");
		$.ajax({
			type : "POST",
			dataType : "json",
			cache : false,
			url : _ctx + "/exch/audit_conn_request.do",
			data : {
				id : id,
				status : status,
				response:response
			},
			success : function(content) {
				if (content.status == '1') {
					ui.msg(content.msg, 1);
					connRequestList();
				} else {
					ui.msg(content.msg, 0);
				}
				$('#myModal').modal('hide');
			},
			error : function() {
				ui.msg('信息加载错误', 0);
			}
		});
	}
	function getRequestDetail(id) {
		$.ajax({
			type : "GET",
			dataType : "html",
			cache : false,
			url : _ctx + "/exch/conn_request_audit.do",
			data : {
				id : id
			},
			success : function(content) {
				$('#myModal').modal('show');
				$('#info').html(content);
			},
			error : function() {
				ui.msg('信息加载错误', 0);
			}
		});
	}
	function changeStatus(val) {
		var html 
		if (val == 0) {
			html = "<textarea datatype='require' msg='请输入反馈内容！' title='必填项,反馈内容' placeholder='请输入反馈内容！' class='form-control '  name='response' id='response' ></textarea>"
		} else {
			html = "&nbsp;<textarea datatype='require' msg='请输入反馈内容！' title='必填项,反馈内容' placeholder='请输入反馈内容！' class='form-control '  name='response' id='response' style='display: none;'>通过</textarea>"
		}
			$("#response_div").html(html);

	}
	function sendRequest() {
		$.ajax({
			type : "POST",
			dataType : "html",
			cache : false,
			url : _ctx + "/registry/node_info_send_request.do",
			success : function(content) {
				$('#myModal').modal('show');
				$('#info').html(content);
			},
			error : function() {
				ui.msg('信息加载错误', 0);
			}
		});
	}
	function sendExchRelRequest(){
		var nodeInstallUrl = $("#nodeInstallUrl").val();
		if(nodeInstallUrl==null ||  nodeInstallUrl==""){
			alert("目的节点部署地址不能为空！");
		}else{
			$("#sendExchRelBtn").attr("disabled","disabled");
			$.ajax({
				type : "POST",
				dataType : "json",
				cache : false,
				 url: _ctx + "/exch/send_exch_rel_request.do", 
				data : {
					nodeInstallUrl :nodeInstallUrl
				},
				success : function(content) {
					if (content.status == '1') {
						ui.msg(content.msg, 1);
					} else {
						ui.msg(content.msg, 0);
					}
					$('#myModal').modal('hide');
					connRequestList();
				},
				error : function() {
					ui.msg('信息加载错误', 0);
				}
			});
		}
		
	}
</script>
<style type="text/css">
/*#trzzDiv {height:320px;overflow-y:scroll;overflow-x:auto;}*/
#trzzDiv {
	height: 50%;
	overflow-y: scroll;
}
</style>
</head>
<body>
	<%@ include file="/WEB-INF/view/common/topbar.jsp"%>
	<div class="main-container" id="main-container">
		<div class="main-container-inner">
			<%@ include file="/WEB-INF/view/common/sidebar.jsp"%>
			<div class="main-content">
				<div class="breadcrumbs" id="breadcrumbs">
					<ul class="breadcrumb">
						<li><i class="icon-home home-icon"></i> <a href="#">首页</a></li>
						<li><a href="#">交换管理</a></li>
						<li><a href="#">交换关系管理</a></li>
						<li class="active">关系信息</li>
					</ul>
				</div>
				<div class="page-content">
					<div class="row">
						<div class="col-sm-12">
							<div class="widget-box ">
								<div class="widget-header header-color-white">
									<div class="widget-toolbar no-border">
											<a class="btn btn-sm btn btn-primary" id="sendRequest"
												href="javascript:void(0);" onclick="sendRequest();" > <i
												class="icon-cogs bigger-120"></i>新建交换关系 </a>
									</div>
								</div>
							</div>
						</div>
						<div class="hr hr24 hr-dotted"></div>
						<div class="col-sm-12">
							<div class="widget-box">
								<ul class="nav nav-tabs">
									<li id="nodeList"><a href="javascript:void(0);"
										class="navbar-link" onclick="nodeInfoList();">已建立交换关系节点</a>
									</li>
									<li id="requestList"><a href="javascript:void(0);"
										class="navbar-link" onclick="connRequestList();">交换节点审核</a>
									</li>
								</ul>
								<div id="data"></div>
								<div id="myModal" class="modal fade" role="dialog" tabindex="-1"
									aria-labelledby="查看" aria-hidden="false">
									<div class="modal-dialog">
										<div class="modal-content">
											<div class="modal-header"></div>
											<div id="info"></div>
											
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>
